import java.util.Scanner;

public class P1980 {
    public static void main(String[] args) {



        Scanner hh=new Scanner(System.in);
        int n=hh.nextInt();
        int x=hh.nextInt();
        int count=0,digit=1;
        while(digit<=n){
            int high=n/(digit*10);
            int current=(n/digit)%10;
            int low=n%digit;
            if(x==0){

                if(high==0){
                    digit*=10;
                    continue;
                }
                high--;
            }
            if(current<x){
                count+=high*digit;
            } else if (current==x) {
                count+=high*digit+low+1;
            }
            else count+=(high+1)*digit;
            digit*=10;
        }

        System.out.print(count);

    }
}
